package com.qingke.oms.command.shop;

import com.qingke.oms.command.ShopCommand;
import com.qingke.oms.pojo.Goods;
import com.qingke.oms.pojo.GoodsStatistic;
import com.qingke.oms.pojo.Shop;
import com.qingke.oms.pojo.User;
import com.qingke.oms.util.OMSConsole;

public class SetPriceCommand extends ShopCommand {

	public SetPriceCommand(User user, Shop shop) {
		super(user, shop);
	}

	@Override
	public void execute() {
		int goodsId=OMSConsole.getInt("goods id:");
		Goods goods=dao.selectGoodsById(goodsId);
		if(goods==null){
			OMSConsole.println("The id of the goods is not existed.");
			return ;
		}
		GoodsStatistic goodsRecord=dao.selectGoodsStatisticByShopAndGoods(shop, goods);
		if(goodsRecord==null){
			OMSConsole.println("There is no the goods in your shop");
			return ;
		}
		double price=OMSConsole.getDouble("price:");
		goodsRecord.setPrice(price);
		boolean isSuccess=dao.updateGoodsStatistic(goodsRecord);
		if(!isSuccess){
			OMSConsole.println("update price failed.");
			return ;
		}
		OMSConsole.println("update price success");
		
	}

}
